<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>修改实际人工</title>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" href="../css/mui.picker.min.css">
	<style type="text/css">
    	.detail{
    		padding-right: 20px!important;
    	}
    	h5,
        label {
            color: #0062CC;
        }

        label {
            font-size: 14px;
        }
    	.mui-navigate-right .mui-col-xs-8{
		    width: 62.666667%!important;
    	}
    	.mui-text-right input,.mui-text-right textarea{
    		border: 0;
    		font-size: 14px;
		    font-weight: 400;
		    color: #8f8f94;
    		margin-bottom: 0;
    		text-align: right;
    	}
    </style>
</head>

<body>
    <div class="mui-content">
		<ul class="mui-table-view mui-table-view-chevron type_list_spair">
			<li class="mui-table-view-cell detail" tapmode onclick="openSaveWin('work_order_sel_tast','选择任务',{wonum: api.pageParam.wonum,linetype: api.pageParam.linetype})">
				<div class="mui-table mui-navigate-right">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">任务：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <span class="mui-h5" id="wonum">请选择任务</span>
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail" tapmode onclick="openSaveWin('work_order_sel_manager','选择人员',{manager:true})">
				<div class="mui-table mui-navigate-right">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">人工：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <span class="mui-h5" id="laborcode">请选择人工</span>
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">名称：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <span class="mui-h5" id="userName"></span>
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail" tapmode onclick="chooseTime('beginTime')">
				<div class="mui-table mui-navigate-right">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">开始时间：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <span class="mui-h5" id="starttime">请选择开始时间</span>
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail" tapmode onclick="chooseTime('endTime')">
				<div class="mui-table mui-navigate-right">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">结束时间：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <span class="mui-h5" id="finishtime">请选择结束时间</span>
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">常规小时数：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <input type="text" onchange="linecost()" placeholder="请输入常规小时数" name="" id="regularhrs" value="" />
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">费率：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <input type="text" onchange="linecost()" placeholder="请输入费率" name="" id="payrate" value="" />
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">行成本：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <span class="mui-h5" id="lineText">0.00</span>
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell mui-checkbox">
                <label>是否批准:</label>
                <input name="checkbox1" id="directreq" type="checkbox" checked="" onchange="isdirectreq()">
            </li>
		</ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/common.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/mui.picker.min.js"></script>
<script type="text/javascript">
	var wonum,beginTime,endTime,startdate,finishdate,genapprservreceipt=1;
	var labtransid;
	apiready = function() {
      LoadDetail();
      api.addEventListener({
          name: 'TastId'
      }, function(ret, err) {
      	wonum = ret.value.tastnum;
        $api.html($api.byId('wonum'), ret.value.description)
      });
      api.addEventListener({
          name: 'ManagerCh'
      }, function(ret, err) {
          $api.html($api.byId('laborcode'), ret.value.userID)
          $api.html($api.byId('userName'), ret.value.userName)
      });


      api.addEventListener({
  		    name:'navitembtn'
  		},function(ret, err){
  	    if(ret.type == 'right'){
          if(wonum == ''|| wonum == null){
            Toast('请选择任务！');
            return
          }
          if($api.html($api.byId('laborcode')) == '请选择人工'){
            Toast('请选择人工！');
            return
          }
          if(beginTime == '' ||　beginTime ==　null){
            Toast('请选择开始时间！');
            return
          }
          if(endTime == '' || endTime == null){
            Toast('请选择结束时间！');
            return
          }

          if(!$api.val($api.byId('regularhrs'))){
            Toast('请输入常规小时数！');
            return
          }
          if(!$api.val($api.byId('payrate'))){
            Toast('请输入费率！');
            return
          }
          ajaxrd("updateLabTrans",{
          	labtransid:labtransid,
            refwo: wonum,
            laborcode: $api.html($api.byId('laborcode')),
            starttime: beginTime,
            finishtime: endTime,
            startdate: startdate,
            finishdate:finishdate,
            regularhrs: $api.val($api.byId('regularhrs')),
            payrate: $api.val($api.byId('payrate')),
            linecost: $api.val($api.byId('regularhrs')) * $api.val($api.byId('payrate')),
            genapprservreceipt: genapprservreceipt
          },function(data){
            Toast('修改成功');
            api.sendEvent({
                name: 'refersh',
                extra: {
                    isrefersh: 'yes'
                }
            });
            setTimeout(function(){
	    		api.closeWin();
	    	},500)
          })
  	    }
    	})
	}
	function chooseTime(type){
	    selectCommonYMDhm(function(data){
	      if(type == 'beginTime'){
	        $api.html($api.byId('starttime'),data);
	        beginTime = data.split(' ')[1];
	        startdate = data.split(' ')[0];
	      }else{
	        $api.html($api.byId('finishtime'),data);
	        endTime = data.split(' ')[1];
	        finishdate = data.split(' ')[0];
	      }
	    })
    }
	var linecost = function () {
		if ($api.val($api.byId('regularhrs')) =='' || $api.val($api.byId('payrate')) == '') {
			return
		}
		$api.text($api.byId('lineText'),$api.val($api.byId('regularhrs')) * $api.val($api.byId('payrate')))
	}
	var isdirectreq = function () {
		if ($api.byId('directreq').checked == false) {
          	genapprservreceipt = 0
          } else {
          	genapprservreceipt = 1
          }
	}
	function LoadDetail() {
      ajaxrd("queryLabTransDetail", {
          wonum:  String(api.pageParam.orderlistnum)
      }, function(ret, err) {
          labtransid = ret.labtransid;
          $api.text($api.byId('wonum'), ret.description);
          wonum = ret.taskid;
          $api.text($api.byId('laborcode'), ret.laborcode);
          $api.text($api.byId('userName'), ret.displayname);
          $api.html($api.byId('starttime'),ret.actstart);
	        beginTime = ret.actstart.split(' ')[1];
	        startdate = ret.actstart.split(' ')[0];
          $api.html($api.byId('finishtime'),ret.actfinish);
	        endTime = ret.actstart.split(' ')[1];
	        finishdate = ret.actstart.split(' ')[0];
          $api.val($api.byId('regularhrs'),ret.regularhrs);
          $api.val($api.byId('payrate'), ret.payrate);
          $api.text($api.byId('lineText'),ret.linecost);
          if (ret.genapprservreceipt == 1) {
          	genapprservreceipt = 1;
          	$api.byId('directreq').checked = true;
          } else {
          	genapprservreceipt = 0;
          	$api.byId('directreq').checked = false;
          }

      })
    }
</script>

</html>
